objList = {}
drawList = {}
bpm = 0
timeDiff = 0
active = 1
curTime = love.timer.getTime()
nextTime = 0

function love.load(arg)
	love.window.setTitle("Metronomo")
	if arg then
		bpm = arg[1] or 80
		print(bpm .. " BPM started")
	end
	for i = 1, 4 do
		local dot = createDots(340 + (i * 30), 300)
		table.insert(objList, dot)
		table.insert(drawList, dot)
	end
	objList[1].isActive = true
	timeDiff = 60 / bpm
	print("timeDiff is defined to be " .. timeDiff)
	nextTime = curTime + timeDiff

	source = love.audio.newSource("05 Be Alright.mp3", "static")
	if arg[2] then
		source:setVolume(tonumber(0.22))
	end
	source:play()
end

function love.update(dt)
	if love.keyboard.isDown("escape") then love.quit() end
	if nextTime <= love.timer.getTime() then
		if active == 4 then
			active = 1
			objList[4].isActive = false
			objList[1].isActive = true
		else
			objList[active].isActive = false
			objList[active + 1].isActive = true
			active = active + 1
		end
		nextTime = love.timer.getTime() + timeDiff
	end
end

function love.draw()
	for i = 1, #drawList do
		if drawList[i].isActive then
			love.graphics.setColor(drawList[i].activeColor)
			love.graphics.circle("fill", drawList[i].x, drawList[i].y, 10)
		else
			love.graphics.setColor(drawList[i].unactiveColor)
			love.graphics.circle("fill", drawList[i].x, drawList[i].y, 10)
		end
	end
end

function love.mousepressed(x, y)
	print("x: " .. x .. "\ny: " .. y)
end

function createDots(x, y)
	local dot = {}
	dot.x = x or 0
	dot.y = y or 0
	dot.isActive = false
	dot.unactiveColor = {1, 1, 1, 1}
	dot.activeColor = {0.86, 0.46, 0.12, 1}
	return dot
end